#include "stdafx.h"
#include <boost/test/auto_unit_test.hpp>
#include <sstream>
#include "detail/bmock_out_str_arg_val.hpp"
#include "detail/bmock_test_control_tools.hpp"
#include "bmock_util.hpp"

namespace bmock {
	static const control_tools_ptr tl(new test_control_tools());
	static const char              name[]   = "arg";
	static const char              s_val1[] = "ABCDEFG";
	static const size_t            LEN      = sizeof(s_val1);

	BOOST_AUTO_TEST_CASE(test_out_str_arg_val_get_value) {
		const arg_val_ptr p_val(make_out_arg_val(name,(char *)s_val1));
		arg_checker       al(tl);
		const arg_val_str expected("",s_val1);

		BOOST_CHECK_EQUAL(expected,p_val->get_value(al));
	}

	BOOST_AUTO_TEST_CASE(test_out_str_arg_val_update) {
		char              s_val2[LEN];
		const arg_val_ptr p_val(make_out_arg_val(name,s_val2));
		arg_checker       al(tl);
		const arg_val_str expected("",s_val1);

		al.set_location(location(__FILE__,__LINE__+1));
		BOOST_CHECK_NO_THROW(p_val->update(al,expected));
		BOOST_CHECK_EQUAL(LEN,mismatch_at(s_val1,s_val1+LEN,s_val2));
	}

	BOOST_AUTO_TEST_CASE(test_out_str_arg_val_print) {
		char              s_val2[sizeof(s_val1)];
		const arg_val_ptr p_val(make_out_arg_val(name,s_val2));
		const std::string      expected = std::string("OUT(")+out_arg_val::UNKNOWN+")";
		std::ostringstream        os;

		strcpy(s_val2,s_val1);
		BOOST_CHECK_NO_THROW(p_val->print(os));
		BOOST_CHECK_EQUAL(expected,os.str());
	}

	struct stam_out_str_arg_val : public out_str_arg_val {
		stam_out_str_arg_val(const char *const n,char *const vp)
			:out_str_arg_val(n,vp)

		{}
		~stam_out_str_arg_val() {}
	};

	BOOST_AUTO_TEST_CASE(test_out_str_arg_val_operator) {
		char * s_val2=new char[2];
		const stam_out_str_arg_val p_val (name,s_val2);
		stam_out_str_arg_val p_val1 (name,s_val2);

		BOOST_CHECK_NO_THROW(p_val1=p_val);

		delete [] s_val2;
	}

}